﻿//----------------------------------------------------------------
// Copyright (C) 2015-2020 PeachSystem Co.,Ltd.
// All rights reserved.
//
// 文件:WebHelper.cs
// 摘要:Web工具类
// 说明:
//

//当前版本：1.0.0
//作    者：陶剑扬
//完成日期：2014-11-07
//----------------------------------------------------------------
using System;
using System.IO;
using System.Web;
using System.Net;
using System.Text;
using System.Linq;
using System.Collections.Generic;

namespace PeachSystem.XWX.Helpers
{
    /// <summary>
    /// Web工具类
    /// </summary>
    public static class WebHelper
    {
        /// <summary>
        /// 获取指定Url的HTML
        /// </summary>
        /// <param name="url">Url</param>
        /// <param name="encoding">字符集名称</param>
        /// <returns>HTML文本</returns>
        public static string GetHTML(string url, string encoding)
        {
            try
            {
                System.Net.WebRequest wReq = System.Net.WebRequest.Create(url);
                System.Net.WebResponse wResp = wReq.GetResponse();
                System.IO.Stream respStream = wResp.GetResponseStream();
                using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.GetEncoding(encoding)))
                {
                    return reader.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
    }
}